﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="true" CodeFile="recObjectionDecisionslist.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recObjectionDecisionslist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" Runat="Server">

<link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveUrl("~/scripts/helper.js") %>" type="text/javascript"></script>
    
    <div>
    <button id="btnAdd" type="button" onclick="OpenForm('add');">
        Tambah</button>
    <button id="btnEdit" type="button" onclick="OpenForm('edit');">
        Ubah</button>
    
    </div>
    
    <br />
    <br /> 
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <div id="dialog" title="Default dialog">
    </div>
    
    <script type="text/javascript">
        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
    </script>
    
    <script type="text/javascript">
        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recObjectionHandler.ashx") %>';
        $('#table').jqGrid({
            url: handlerUrl + '?method=GetDataDecision',
            datatype: 'json',
            colNames: ['invoiceno', 'Objection ID', 'Debitur', 'No Permohonan', 'No. Sanksi', 'Jumlah Sanksi (Rp)',  'No. Tanggapan', 'Tgl. Tanggapan', 'No. Keputusan', 'Tgl. Keputusan', 'Keputusan', 'Jumlah Keputusan (Rp)', 'Catatan', 'Status', 'Lampiran' ],
            colModel: [
                    { name: 'recSanction.InvoiceNo', hidden: true, index: 'recSanction.InvoiceNo', align: 'left', width: 100 },
                    { name: 'ObjectionID', hidden: true, index: 'ObjectionID', align: 'left', width: 100 },
                    { name: 'recDebtor.DebtorName', index: 'recDebtor.DebtorName', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'ObjectionNo', index: 'ObjectionNo', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'SanctionNo', index: 'SanctionNo', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'SanctionValue', index: 'SanctionValue', formatter: 'number', searchtype: 'number' , align: 'right', width: 150 },
                    { name: 'ResponNo', index: 'ResponNO', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'ResponDate', index: 'ResponDate', align: 'center', searchoptions: { sopt: ['eq', 'cn']} , width: 95, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'DecisionNo', index: 'DecisionNo', align: 'center', searchoptions: { sopt: ['eq', 'cn']} , width: 100 },
                    { name: 'DecisionDate', index: 'DecisionDate', align: 'center', width: 95, formatter: 'date', searchoptions: { sopt: ['eq', 'cn']} , formatoptions: { newformat: 'd M Y'} },
                    { name: 'Decision', index: 'Decision', align: 'center', width: 90, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'DecisionValue', index: 'DecisionValue', formatter: 'number', align: 'right', searchtype: 'number' , width: 150 },
                    { name: 'DecisionNote', index: 'DecisionNote', align: 'center', width: 100, searchoptions: { sopt: ['eq', 'cn']}  },
                    { name: 'TransStatus', index: 'TransStatus', align: 'center', width: 50 },
                    { name: 'ObjectionID', index: 'ObjectionID', align: 'center', width: 75, search: false, formatter: returnMyLink }
                    //{ name: 'DecisionValue', hidden: true, index: 'DecisionValue', formatter: 'number', searchtype: 'number' , align: 'right', width: 150 },
           	],
            rowNum: 10,
            id: 'ObjectionID',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'recObjection.CreatedDate',
            sortorder: "desc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1250,
            height: '100%',
            caption: 'Keputusan Keberatan',
            ajaxGridOptions: { cache: false },
//            ondblClickRow: function () {
//                OpenForm('edit');
//            }
        });

        function returnMyLink(cellValue, options, rowdata) {
        
            return "<a  href='#' onclick='downloadfile(" + cellValue + ")' >download</a>";
        
        }

        function downloadfile(cellValue) {
            var objrecImposition = new Object();
            objrecImposition.ObjectionID = encodeURIComponent(cellValue);
            jsonData = JSON.stringify(objrecImposition);
            var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/loaddata/downloadhandler.ashx") %>';
            $.ajax({
                type: 'POST',
                url: handlerUrl + "?method=checkfiledecision",
                contentType: 'application/json',
                dataType: 'json',
                data: jsonData,
                success: function (data) {
                    if (data.IsSuccess) {
                        var win = window.open(handlerUrl + '?method=downloaddecision&ObjectionId=' + cellValue, '_blank');
                        win.focus();
                    }
                    else {
                        alert(data.Message);
                    }
                },
                error: function (response) {
                    //var r = JSON.parse(response.responseText);
                    alert("Error saat download file!"); //Message: " + r.Message);
                }
            });

        }


        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveUrl("~/forms/Transaction/recObjectionDecisionsForm.aspx") %>';
            //            var formUrl1 = '<%= ResolveUrl("~/forms/transaction/recPaymentLoadRekKoranform.aspx") %>';
            //            var formUrl2 = '<%= ResolveUrl("~/forms/transaction/recPaymentAutoRekonsiliasiform.aspx") %>';
            //            var formUrl3 = '<%= ResolveUrl("~/forms/transaction/recPaymentUpdateform.aspx") %>';
            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
                selTextDecisionNo = [];
                selTextSanctionValue = [];
                selTextDecisionValue = [];
                //selTextInvoiceNo = [];
                        $.each(selIds, function () {
                            selText.push(grid.jqGrid('getCell', this, 'ObjectionID'));
                            selTextDecisionNo.push(grid.jqGrid('getCell', this, 'DecisionNo'));
                            selTextSanctionValue.push(grid.jqGrid('getCell', this, 'SanctionValue'));
                            selTextDecisionValue.push(grid.jqGrid('getCell', this, 'DecisionValue'));
                            //selTextInvoiceNo.push(grid.jqGrid('getCell', this, 'recSanction.InvoiceNo'));
                        });



            if (ctl == 'edit') {
                if (selIds.length == 0) {
                    alert('Pilih data yang mau di ubah !');
                }
                else {
                if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else if (selText.length == 1 && selTextDecisionNo != '' ) {
                 $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>' + '&isedit=1&isvalue=' + selTextSanctionValue + '&isdecision=' + selTextDecisionValue  ).dialog({ autoOpen: false, modal: false, width: 550, height: 420, title: 'Ubah Keputusan Keberatan' });
                    $("#dialog").dialog('open');
                } 
//                else if (selTextInvoiceNo != '')
//                {
//                    alert('Data yang anda pilih tidak dapat di edit!\nKarena sudah melakukan pembayaran.');
//                }
                else{
                    alert('Data yang anda pilih tidak dapat di edit!\nSilahkan tambahkan keputusan keberatan dahulu pada data tersebut.');
                     }
                }
            }

            else if (ctl == 'add') {
            if (selIds.length == 0) {
                alert('Pilih data yang akan di tambah !');
            }
                else {
                if (selIds.length > 1) {
                    alert('Pilih satu data untuk tambah.'); 
                }
                else if (selText.length == 1 && selTextDecisionNo == '') {
                
                    $('#dialog').load(formUrl + '?id=' + selText + '&menuId=' + '<%= base.MenuID %>' + '&isedit=0&isvalue=' + selTextSanctionValue ).dialog({ autoOpen: false, modal: false, width: 550, height: 420, title: 'Tambah Keputusan Keberatan' });
                    $("#dialog").dialog('open');
                    }
                else {
                    alert('Data yang anda pilih sudah di tambahkan keputusan keberatan.');
                 }
                }
            
            }

            else {

                if (selIds.length == 0)
                    alert('Pilih data yang mau di hapus !');
                else {
                    var result = window.confirm('Benar data akan di hapus ?');
                    if (result) {

                        var objrecPayment = new Object();
                        //                        objrecPayment.PaymentID = encodeURIComponent(selText);
                        //                        jsonData = JSON.stringify(objrecPayment);
                        //                        CallAjax('<%= ResolveUrl("~/ajaxhandler/transaction/recPaymenthandler.ashx") %>', "?method=delete", jsonData);
                        //                        setTimeout("$('#table').trigger('reloadGrid');", 3000);
                    }
                }

            }
        }
        
    </script>
    <br />
    <br />
    <br />
    <br />

</asp:Content>

